package com.ms.module.wechat.clear;

import android.app.Activity;
import android.content.Intent;

import com.ms.module.wechat.clear.activity.ModuleWeChatClearActivity;
import com.ms.module.wechat.clear.internal.ICloseListener;
import com.ms.module.wechat.clear.internal.WeChatClearCommonn;
import com.ms.module.wechat.clear.repository.SharedPreferencesData;
import com.ms.module.wechat.clear.repository.WeChatScanDataRepository;

import com.ms.module.wechat.clear.utils.ClearTempFileUtils;
import com.ms.module.wechat.clear.utils.WeChatUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 微信清理模块
 */
public class WeChatClearModule {

    public static void start(Activity activity, IWeChatClearListener callBack) {

        if (activity == null) {
            throw new NullPointerException("activity null");
        }
        WeChatClearCommonn.weChatClearCallBack = callBack;

        // 判断是否安装了微信
        if (!WeChatUtils.isWeixinAvilible(activity)) {
            if (WeChatClearCommonn.weChatClearCallBack != null) {
                WeChatClearCommonn.weChatClearCallBack.onNotInstallWeChat();
            }
            return;
        }

        WeChatScanDataRepository.getInstance().clear();
        activity.startActivity(new Intent(activity, ModuleWeChatClearActivity.class));

        // 清除临时文件
        ClearTempFileUtils.clear(activity);
    }


    public static void close() {
        for (ICloseListener it : WeChatClearCommonn.getCloseListeners()) {
            if (it != null) {
                it.close();
            }
        }
    }
}
